<template>
  <div class="img" :style="note">

    <div style="width: 450px;height: 900px;background-color: rgba(0,0,0,0.01);margin:0px auto;text-align: center;position: relative">
      <div style="width: 450px;height: 700px;background-color: rgba(0,0,0,0.6);text-align: center;position: absolute;margin-top: 100px">
        <p style="font-size: 28px;font-family: '楷体';padding-top: 20px;color: slategray">对组队工作室需求</p>
        <hr style="width: 90%;height: 0.01px"/>
        <div style="margin-top: 20px">
          <div style="width: 100%">
            <form style="width: 100%">
              <p style="width: 100%;margin-left: 150px; text-align: left;color: slategray">请上传工作室头像</p>
              <input type="file" @change="getFile($event)"style="color: slategray">
              <button class="button button-primary button-pill button-small" @click="submit($event)">提交</button>
            </form>
          </div>
          <div style="margin-top: 40px">
            <el-input v-model="InputPrice" placeholder="请输入价格" style="width: 70%;margin-top: 30px"></el-input>
            <el-input type="textarea" :rows="2" placeholder="请输入对工作室的要求和工作室的任务" v-model="textarea" style="width: 70%;margin-top: 30px" ></el-input>
          </div>

          <div style="width: 100%">
            <form style="width: 100%">
              <p style="width: 100%;margin-left: 90px; text-align: left;color: slategray">请将工作室的要求和任务以文件上传</p>
              <input type="file" @change="getFilee($event)">
              <button class="button button-primary button-pill button-small" @click="submite($event)">提交</button>
            </form>
          </div>

          <div style="width: 100%">
            <el-button plain style="margin-top: 20px;width: 100px" size="small" @click="register()">添加</el-button>
          </div>

        </div>
      </div>
    </div>

  </div>
</template>

<script>
  export default {
    data() {
      return {
        note: {
          backgroundImage: "url(" + require("../../assets/img/starrr.jpg") + ")",
          backgroundRepeat: "no-repeat",
          backgroundSize: "1890px 1500px",
        },
        tid:'',
        InputPrice:'',
        textarea: '',
        file: '',
        filee: '',
      }
    },
    methods: {

      getFile: function (evente) {
        this.file = event.target.files[0];
        console.log(this.file);
      },
      getFilee: function (event) {
        this.filee = event.target.files[0];
        console.log(this.filee);
      },
      submit: function (event) {
        //阻止元素发生默认的行为
        var _this=this
        event.preventDefault();
        let formData = new FormData();
        console.log(formData)
        formData.append("file", this.file)
        axios.post('/upload/singlefile', formData)
          .then(function (response) {
            alert("上传成功");
            console.log(response);
            var a= response.data;
            //var e=a.split("*");
            //console.log(e[1])
            _this.file=a;
            // window.location.reload();
          })
          .catch(function (error) {
            alert("上传失败");
            console.log(error);
            //window.location.reload();
          });
      },
      submite: function (event) {
        var _this=this
        //阻止元素发生默认的行为
        event.preventDefault();
        let formData = new FormData();
        console.log(formData)
        formData.append("file", this.filee)
        axios.post('/upload/singlefile', formData)
          .then(function (response) {
            alert(response.data);
            console.log(response);
            var a= response.data;
            //  var e=a.split("*");
            // console.log(e[1])
            _this.filee=a;
          })
          .catch(function (error) {
            alert("上传失败");
            console.log(error);
            //window.location.reload();
          });
      },

      register(){
          this.tid = this.$route.query.mallCode
          axios.post('/workroom/insertTeamDemand',{
            tid:this.tid,
            demand:this.textarea,
            price :this.InputPrice,
            photo :this.file,
            doc:this.filee
          }).then((response) => {
            if(response.data.states==800){
              this.$notify({
                title: '成功',
                message: '注册成功',
                type: 'success',
                duration:1000
              });
              this.$router.replace({
                path: '/TeamMember',
                query: {
                  mallCode: this.tid,
                }
              })

             // this.$router.replace('/Index')
            }else{
              this.$notify.error({
                title: '错误',
                message: response.data.message,
                type: 'warning',
                duration:0
              });
            }
          }).catch((response)=>{

          })
        }

      },






  }
</script>

<style scoped>

</style>
